﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Handrise.CDCable.Business
{
    public class GISService
    {
        /// <summary>
        /// 获取地图数据文件大小
        /// </summary>
        /// <returns></returns>
        public long GetGISDataLen()
        {
            string fileName = CommonFunction.GetLocalPath() + "\\GISData\\MapCache.gd";
            FileInfo fi = new FileInfo(fileName);
            return fi.Length;
        }

        /// <summary>
        /// 同步地图数据
        /// </summary>
        /// <param name="beginIndex"></param>
        /// <param name="buffer"></param>
        /// <returns></returns>
        public bool SynchronizeGISData(int beginIndex, out byte[] buffer)
        {
            string fileName = CommonFunction.GetLocalPath() + "\\GISData\\MapCache.gd";
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            int len;
            if ((fs.Length - 1024 * 100 * beginIndex) > 1024 * 100)
                len = 1024 * 100;
            else
                len = (int)fs.Length - 1024 * 100 * beginIndex;

            buffer = new byte[len];

            fs.Position = 1024 * 100 * beginIndex;
            fs.Read(buffer, 0, len);
            fs.Close();

            return true;
        }
    }
}
